package com.qf.zyh.web.controller;

import com.qf.zyh.entity.TUsers;
import com.qf.zyh.services.TUsersSer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/user")
public class users extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        TUsersSer ts = (TUsersSer) ac.getBean("ts");
        TUsers getname = ts.getname(username, password);
        System.out.println(getname);
        if (getname!=null) {
            List<TUsers> getall = ts.getall();
            System.out.println(getall);
            req.setAttribute("list",getall);
            req.getRequestDispatcher("index.jsp").forward(req,resp);
        }

    }
}
